package cn.inyaa.admin.blog.controller;

import cn.inyaa.admin.blog.bean.InyaaBlog;
import cn.inyaa.admin.blog.dto.InyaaBlogDto;
import cn.inyaa.admin.blog.service.InyaaBlogService;
import cn.inyaa.admin.blog.vo.InyaaBlogArchiveVo;
import cn.inyaa.admin.blog.vo.InyaaBlogVo;
import com.inyaa.base.bean.BaseResult;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

@RestController
@RequestMapping("/blog")
@RequiredArgsConstructor
public class InyaaBlogController {

    private final InyaaBlogService inyaaBlogService;

    @PostMapping("/save")
    public BaseResult<String> save(@RequestBody InyaaBlogDto blog, Principal principal) {
        inyaaBlogService.save(blog, principal);
        return BaseResult.success();
    }

    @GetMapping("/list")
    public BaseResult<List<InyaaBlog>> list(InyaaBlog req) {
        return BaseResult.success(inyaaBlogService.findAll(req));
    }

    @PostMapping("/delete")
    public BaseResult<String> delete(@RequestBody InyaaBlog blog) {
        inyaaBlogService.delete(blog);
        return BaseResult.success();
    }

    @GetMapping("/info")
    public BaseResult<InyaaBlogDto> info(InyaaBlog blog) {
        return BaseResult.success(inyaaBlogService.getBlogInfo(blog));
    }

    @GetMapping("/archive/list")
    public BaseResult<List<InyaaBlogArchiveVo>> archive() {
        return inyaaBlogService.archive();
    }

    @GetMapping("/findBlogList")
    public BaseResult<Page<InyaaBlogVo>> findBlogList(InyaaBlogDto req) {
        return BaseResult.success(inyaaBlogService.findBlogListPage(req));
    }
}
